home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / intuisup.lha / Intuisup / source.lha / Editor / fonts.c < prev    next >
C/C++ Source or Header  |  1992-10-02  |  4KB  |  187 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: fonts.c
  6.  *    Created ..: Tuesday 31-Dec-91 14:29:10
  7.  *    Revision .: 1
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    07-Jan-92   Torsten Jürgeleit      update to new ISUP font routines
  12.  *    31-Dec-91   Torsten Jürgeleit      Created this file!
  13.  *
  14.  ****************************************************************************
  15.  *
  16.  *    Font support routines
  17.  *
  18.  * $Revision Header ********************************************************/
  19.  
  20.  /* Includes */
  21.  
  22. #include "includes.h"
  23. #include "defines.h"
  24. #include "imports.h"
  25. #include "protos.h"
  26.  
  27.  /* Open template font with given attributes */
  28.  
  29. struct TextAttr *
  30. open_template_font_by_attributes(struct TemplateList *tl, BYTE * name,
  31.                                  USHORT ysize)
  32. {
  33.     struct TextAttr search_ta, *avail_ta, *ta = NULL;
  34.  
  35.     /* Try to open given font */
  36.     search_ta.ta_Name = (STRPTR) name;
  37.     search_ta.ta_YSize = ysize;
  38.     search_ta.ta_Style = FS_NORMAL;
  39.     search_ta.ta_Flags = FPF_ROMFONT;
  40.     if (avail_ta = IAskFont(pri, &search_ta))
  41.     {
  42.         struct TemplateFont *tf;
  43.  
  44.         /* Search given template font in font list */
  45.         ysize = avail_ta->ta_YSize;
  46.         for (tf = get_head((struct List *) & tl->tl_Fonts); tf;
  47.              tf = get_succ((struct Node *) & tf->tf_MinNode))
  48.         {
  49.             if (!strcmp(name, (BYTE *) tf->tf_TextAttr.ta_Name) &&
  50.                 ysize == tf->tf_TextAttr.ta_YSize)
  51.             {
  52.                 tf->tf_UseCount++;
  53.                 ta = &tf->tf_TextAttr;
  54.                 break;
  55.             }
  56.         }
  57.         if (!ta)
  58.         {
  59.  
  60.             /* Create new template font */
  61.             if (tf = AllocMem((LONG) sizeof(struct TemplateFont),
  62.                                (LONG) MEMF_PUBLIC))
  63.             {
  64.                 if (duplicate_string(name, (BYTE **) & tf->tf_TextAttr.ta_Name) !=
  65.                     EDITOR_STATUS_NORMAL)
  66.                 {
  67.                     FreeMem(tf, (LONG) sizeof(struct TemplateFont));
  68.                 }
  69.                 else
  70.                 {
  71.  
  72.                     /* Init template font and add it to font list */
  73.                     ta = &tf->tf_TextAttr;
  74.                     ta->ta_YSize = avail_ta->ta_YSize;
  75.                     ta->ta_Style = avail_ta->ta_Style;
  76.                     ta->ta_Flags = avail_ta->ta_Flags;
  77.                     tf->tf_UseCount = 1;
  78.                     AddTail((struct List *) & tl->tl_Fonts,
  79.                             (struct Node *) & tf->tf_MinNode);
  80.                 }
  81.             }
  82.         }
  83.     }
  84.     return (ta);
  85. }
  86.  
  87.  /* Open template font with given number */
  88.  
  89. struct TextAttr *
  90. open_template_font_by_num(struct TemplateList *tl, USHORT num)
  91. {
  92.     struct TemplateFont *tf;
  93.     struct TextAttr *ta;
  94.  
  95.     /* Search given template font in font list */
  96.     if (!(tf = get_node((struct List *) & tl->tl_Fonts, num)))
  97.     {
  98.         ta = NULL;
  99.     }
  100.     else
  101.     {
  102.         tf->tf_UseCount++;
  103.         ta = &tf->tf_TextAttr;
  104.     }
  105.     return (ta);
  106. }
  107.  
  108.  /* Get number of template font from font list */
  109.  
  110. USHORT
  111. get_template_font_num(struct TemplateList * tl, struct TextAttr * ta)
  112. {
  113.     struct TemplateFont *tf;
  114.     USHORT num = 0;
  115.  
  116.     /* Search given template font in font list */
  117.     for (tf = get_head((struct List *) & tl->tl_Fonts); tf;
  118.          tf = get_succ((struct Node *) & tf->tf_MinNode))
  119.     {
  120.         if (ta == &tf->tf_TextAttr)
  121.         {
  122.             break;
  123.         }
  124.         else
  125.         {
  126.             num++;
  127.         }
  128.     }
  129.     return (num);
  130. }
  131.  
  132.  /* Close template font with given attributes */
  133.  
  134. VOID
  135. close_template_font(struct TemplateList * tl, struct TextAttr * ta)
  136. {
  137.     if (ta)
  138.     {
  139.         struct TemplateFont *tf;
  140.  
  141.         /* Search given template font in font list */
  142.         for (tf = get_head((struct List *) & tl->tl_Fonts); tf;
  143.              tf = get_succ((struct Node *) & tf->tf_MinNode))
  144.         {
  145.             if (ta == &tf->tf_TextAttr)
  146.             {
  147.  
  148.                 /* Close font and check if its in use yet */
  149.                 if (!--tf->tf_UseCount)
  150.                 {
  151.  
  152.                     /* Remove and free template font from font list */
  153.                     Remove((struct Node *) & tf->tf_MinNode);
  154.                     free_template_font(tf);
  155.                 }
  156.                 break;
  157.             }
  158.         }
  159.     }
  160. }
  161.  
  162.  /* Free template font list */
  163.  
  164. VOID
  165. free_font_list(struct TemplateList *tl)
  166. {
  167.     struct TemplateFont *tf;
  168.     struct List *list = (struct List *) & tl->tl_Fonts;
  169.  
  170.     while (tf = (struct TemplateFont *) RemHead(list))
  171.     {
  172.         free_template_font(tf);
  173.     }
  174. }
  175.  
  176.  /* Free template font */
  177.  
  178. VOID
  179. free_template_font(struct TemplateFont *tf)
  180. {
  181.     if (tf)
  182.     {
  183.         free(tf->tf_TextAttr.ta_Name);
  184.         FreeMem(tf, (LONG) sizeof(struct TemplateFont));
  185.     }
  186. }
  187.